package xyz.scootaloo.oj.leetcode

import xyz.scootaloo.oj.ds.ListNode
import java.util.*

/**
 * @author flutterdash@qq.com
 * @since 2021/4/8 14:28
 */
class P92 {

    /**
     *      |           |
     *      1,  2,  3,  4,  5
     *  0,  1,  2,  3,  4,  5
     */
    fun reverseBetween(head: ListNode?, left: Int, right: Int): ListNode? {
        if (head == null ) return null
        if (left == right) return head
        fun it(node: ListNode, count: Int, rHead: ListNode, rTail: ListNode): ListNode {
            if (count == 0) {
                rHead.next = node
                rTail.next = node.next
                return node
            }
            val tail = it(node.next, count - 1, rHead, rTail)
            tail.next = node
            return tail
        }

        val vHead = ListNode(0)
        vHead.next = head
        val stack = Stack<ListNode>()
        stack.push(vHead)

        var pos = 0
        var point = head
        while (pos < (left - 1)) {
            point = point?.next
            pos++
        }

//        it(point?.next, (right - left), point, )
        return null
    }

}
